#include "Xavi.h"

void __stdcall MoveTo(MOVEPAR* varPoint)
{
	varPoint->unknow1=0;
	varPoint->unknow2=0;
	varPoint->flag=4;
	__asm
	{
		push	varPoint
		call		pMovetoCall
		add		esp,	4
	}
}

OBJECTGUID GetObjectGuid(char* szObjName)
{
	//char szPlayer[]="player";
	ULONG PlayerPtr = (ULONG) szObjName;
	OBJECTGUID objGUID;
	__asm
	{
		pushad
			mov	eax,PlayerPtr
			push	eax
			call		GetGuidCall
			mov	objGUID.hDword,edx
			mov	objGUID.lDword, eax
			add		esp,4
			popad
	}
	return objGUID;
}

OBJECTGUID GetPlayerGuid()
{
	char szPlayer[] = "player";
	OBJECTGUID objPlayerGuid;
	objPlayerGuid = GetObjectGuid(szPlayer);
	return objPlayerGuid;
}

DWORD __stdcall GetPlayerBase(OBJECTGUID objGUID)
{
	OBJECTGUID tmpobjGUID = objGUID;
	OBJECTGUID* pobjGUID = &tmpobjGUID;
	DWORD pBase=0;
	__asm
	{
		pushad
			push	pobjGUID
			push	objGUID.lDword
			mov	ecx,	pGetBasethis
			mov	ecx, dword ptr [ecx]
		call		pGetBaseCall
			mov	pBase,	eax
			popad
	}
	return pBase;
}
COORDINATE __stdcall GetPlayerCoord(DWORD pBase)
{
	COORDINATE tmpCoord;
	__asm
	{
		pushad
		mov	eax,	pBase
		mov	eax, dword ptr [eax+0xe4]
		add		eax, 0x10
		mov	ebx, dword ptr [eax]
		mov	tmpCoord.x,ebx
		mov	ebx, dword ptr [eax + 4]
		mov	tmpCoord.y,ebx
		mov	ebx, dword ptr [eax + 8]
		mov	tmpCoord.z, ebx
		popad
	}
	return tmpCoord;
}
void __stdcall SetPlayerAngle(DWORD pBase, float angle)
{
	__asm
	{
		pushad
		mov	eax,	pBase
		mov	eax, dword ptr [eax+0xe4]
		add		eax, 0x20
		mov	ebx,angle
		mov	dword ptr [eax], ebx
		popad
	}
}

void InitAddress()
{
	HMODULE hMain = GetModuleHandle(NULL);
	ULONG ulWowBase = (ULONG)hMain;

	GetGuidCall = ulWowBase + player_guid_call_offest;
	pGetBaseCall = ulWowBase + player_base_call_offest;
	pGetBasethis = ulWowBase + player_base_this_offest;
	pMovetoCall = ulWowBase + player_move_call_offest;

}